<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//用户表
class Search_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->bbs_article = 'bbs_article';
        $this->bbs_article_category = 'bbs_article_category';
    }
    function topinfo($kw){
        /*$this->db->select($this->bbs_article.'.*,'.$this->bbs_article_category.'.name');
        $this->db->from($this->bbs_article);
        $this->db->join($this->bbs_article_category,$this->bbs_article_category.'.id='.$this->bbs_article.'.cat_id',left);
        $this->db->where($where);
        $this->db->like($this->bbs_article.'.title',$kw,'both');
        $this->db->or_like($this->bbs_article.'.content',$kw,'both');*/
        $sql="SELECT tan_bbs_article.*,tan_bbs_article_category.name,tan_bbs_article_category.code,tan_bbs_article_category.group,tan_users_info.nickname FROM (tan_bbs_article) LEFT JOIN tan_bbs_article_category ON tan_bbs_article_category.id=tan_bbs_article.cat_id LEFT JOIN tan_users_info ON tan_users_info.user_id=tan_bbs_article.authorid WHERE (tan_bbs_article.title LIKE '%$kw%' OR tan_bbs_article.content LIKE '%$kw%') AND tan_bbs_article.hot = 1 AND tan_bbs_article.show = 1 AND tan_bbs_article.status = 1 order by tan_bbs_article.create_time desc";
        //$this->db->query($sql);
        
        return $this->db->query($sql)->result_array();
    }
    function postcount($kw){
        $sql="SELECT tan_bbs_article.*,tan_bbs_article_category.name,tan_users_info.nickname FROM (tan_bbs_article) LEFT JOIN tan_bbs_article_category ON tan_bbs_article_category.id=tan_bbs_article.cat_id LEFT JOIN tan_users_info ON tan_users_info.user_id=tan_bbs_article.authorid WHERE (tan_bbs_article.title LIKE '%$kw%' OR tan_bbs_article.content LIKE '%$kw%')  AND tan_bbs_article.status = 1";
        return $this->db->query($sql)->num_rows();
    }
    function posts($kw,$page,$limit){
        $sql="SELECT tan_bbs_article.*,tan_bbs_article_category.name,tan_bbs_article_category.code,tan_bbs_article_category.group,tan_users_info.nickname FROM (tan_bbs_article) LEFT JOIN tan_bbs_article_category ON tan_bbs_article_category.id=tan_bbs_article.cat_id LEFT JOIN tan_users_info ON tan_users_info.user_id=tan_bbs_article.authorid WHERE (tan_bbs_article.title LIKE '%$kw%' OR tan_bbs_article.content LIKE '%$kw%')  AND tan_bbs_article.status = 1  AND tan_bbs_article.hot = 0  AND tan_bbs_article.show = 1 order by tan_bbs_article.create_time desc limit $page,$limit";
        return $this->db->query($sql)->result_array();
    }
}
